package 题目集.二分;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Scanner;

/**
 * 先排序（降序），计算前缀和，通过二分找需要几个
 */
//https://vjudge.net.cn/contest/613789#problem/A
public class ch04_超级书架 {
    static Integer[] nums;    //奶牛
    static int[][] pre;     //前缀和，0位置表示高度，1位置表示人数
    static int n;
    static int m;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n = sc.nextInt();
        m=sc.nextInt();

        nums=new Integer[n];
        pre=new int[n][];
        for (int i = 0; i < nums.length; i++) {
            nums[i]=sc.nextInt();
        }
        Arrays.sort(nums,(a,b)->b-a);
        pre[0]=new int[]{nums[0],1};
        for (int i = 1; i < pre.length; i++) {
            pre[i]=new int[]{pre[i-1][0]+nums[i],i+1};
        }
        System.out.println(findSearch(m));
    }

    /**
     * 查找第一个大于等于m的数
     */
    public static int findSearch(int m){
        int l=0,r=n-1;
        while (l <= r) {
            int mid=l+r>>1;
            if (pre[mid][0]>=m){
                r=mid-1;
            }else {
                l=mid+1;
            }
        }
        if (r>=0&&pre[r][0]>=m){
            return pre[r][1];
        }
        if (l<n&&pre[l][0]>=m){
            return pre[l][1];
        }
        return -1;
    }
    static class Reader {
        private static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                return in.nextToken();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
